package com.kunzai.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kunzai.server.mapper.DishMapper;
import com.kunzai.server.pojo.Dish;
import com.kunzai.server.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DishServiceimpl extends ServiceImpl<DishMapper, Dish> implements DishService {

    /**
     * 根据菜品名称查询出来菜品详情
     * @param dishName
     * @return
     */
    @Override
    public Dish selectName(String dishName) {

        if (dishName!=null){
            LambdaQueryWrapper<Dish> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(dishName!=null,Dish::getName,dishName);
            Dish one = this.getOne(queryWrapper);
            return one;
        }

        Dish dish = new Dish();
        dish.setName("草拟吗你到底想查询什么东西");
        return dish;
    }


    /**
     * 模糊查询出来菜品并进行自然排序
     *
     * @param dishNme
     * @return
     */
    @Override
    public Set<Dish>  selectLike(String dishNme) {

        LambdaQueryWrapper<Dish> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(dishNme!=null,Dish::getName,dishNme);
        List<Dish> listDish = this.list(queryWrapper);
        TreeSet<Dish> collect = listDish.stream().collect(Collectors.toCollection(TreeSet::new));
        Iterator<Dish> iterator = collect.iterator();
        while (iterator.hasNext()==true){
            Dish next = iterator.next();
            System.err.println(next);
        }

        return collect;
    }
}








